<template>
	<view style="height: 100vh;position: relative;background-color: #F6FAFA;">
		<view style="padding-left: 40rpx;background-color: #FFFFFF;padding-bottom: 20rpx;">
			<view style="font-size: 35rpx;font-weight: bold;margin-top: 30rpx;margin-bottom: 30rpx;">我的购药清单</view>
			<view class="my-yao" v-for="(recipeItem,recipeIdx) in doctorNormalRecipeDrug" :key="recipeIdx">
				<view>{{recipeItem.drugName}}<text style="margin-right: 20rpx;"></text> {{recipeItem.drugSpecificationName}}</view>
				<view>*{{recipeItem.drugNum}}</view>
			</view>
		</view>
		<view style="padding-left: 40rpx;background-color: #FFFFFF;padding-bottom: 20rpx;margin-top: 20rpx;padding-top: 20rpx;">
			<view style="font-size: 35rpx;font-weight: bold;">{{medOfficinaInfoName}}</view>
			<view class="drug-row" v-for="(drugItem,drugIdx) in drugList" :key="drugIdx">
				<view style="display: flex;align-items: center;">
					<checkbox :value="drugItem.drugId" checked="true" style="transform:scale(0.7)" color="#BE965B"/>
					<view>{{drugItem.drugName}}<text style="margin-right: 20rpx;"></text> {{drugItem.drugSpecificationName}}</view>
				</view>
				<view>{{drugItem.num}}</view>
				<view>{{drugItem.drugPrice}}</view>
			</view>
		</view>
		<view style="position: fixed;bottom: 0rpx;width: 100vw;display: flex;font-size: 35rpx;">
			<view style="width: 50%;background-color: #FFFFFF;height: 100rpx;line-height: 100rpx;padding-left: 40rpx;">
				<text>合计：</text>
				<text style="color: #FEA14F;font-weight: bold;">￥{{allPrice}}</text>
			</view>
			<view v-if="drugList.length>0" style="width: 50%;text-align: center;background: #BE965B;color: #FFFFFF;height: 100rpx;line-height: 100rpx;" @click="isShowTip=true">确认复购</view>
			<view v-else style="width: 50%;text-align: center;background: #BE965B;color: #FFFFFF;height: 100rpx;line-height: 100rpx;">确认复购</view>
		</view>
		
		<view class="win flex" v-if="isShowTip" @touchmove.stop="">
			<view style="margin: auto;background-color: #FFFFFF;border-radius: 20rpx;width: 90%;height: 300rpx;display: flex;flex-direction: column;align-items: center;justify-content: space-around;">
				<view style="font-size: 38rpx;text-align: center;font-weight: bolder;">温馨提示</view>
				<view style="font-size: 34rpx;text-align: center;">您所选购的药品将由第三方单位配送</view>
				<view style="display: flex;flex-direction: row;align-items: center;justify-content: space-around;align-items: center;width: 100%;">
					<button type='primary' style="background-color: #F3F3F3;width: 40%;color: #000000;height: 90rpx;line-height: 90rpx;font-size: 30rpx;" @click="isShowTip=false">
						取消
					</button>
					<button type='primary' style="background-color: #BE965B;width: 40%;height: 90rpx;line-height: 90rpx;font-size: 30rpx;" @click="sendRepRecipe">
						确定
					</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShowTip:false,
				wx: "https://app.mzmzb.com",
				current: 1,
				hasNextPage: true, //是否有下一页
				message: 'more',
				allDocList: [],
				recipieList: [],
				contentText: {
					contentdown: "点击显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				},
				medOfficinaInfoName:'',
				medOfficinaInfoId:'',
				recipeId:'',
				doctorNormalRecipeDrug:[],
				drugList: [],
				allPrice: 0,
				usrUserId:undefined
			};
		},
		onLoad(options) {
			// console.log(options)
			this.medOfficinaInfoName = options.medOfficinaInfoName
			this.medOfficinaInfoId = options.medOfficinaInfoId
			this.recipeId = options.recipeId
			this.doctorNormalRecipeDrug = JSON.parse(options.doctorNormalRecipeDrug)
			this.usrUserId = options.usrUserId
			this.getDrugListByRecipeId();
		},
		methods: {
			sendRepRecipe(){
						let data ={
							recipeId: this.recipeId,
							medOfficinaInfoId: this.medOfficinaInfoId,
							usrUserId: this.usrUserId
						}
						this.func.$request('repRecipe/sendRepRecipe.tz',data,'GET').then(res=>{
							if (res.data.success = true) {
								uni.showToast({
									title: '操作成功！',
									icon: 'success',
									duration: 3000
								})
								
								// uni.redirectTo({
								// 	url: '/pages/myrecipe/index'
								// });
								
								uni.navigateTo({
									url: '/pages3/chufangcg/index?msg=复购成功'
								})
								// uni.setStorageSync("usrUserId",test_account)
								// let id = this.$im.conn.getUniqueId();
								// let msg = new this.$im.message('txt', id);
								// msg.set({
								// 	to: this.from,
								// 	from: this.to,
								// 	msg: '续方',
									// roomType: false,
									// chatType: 'singleChat',
								// 	success(){
								// 		console.log('续方通知成功了')
								// 	},
								// 	fail(){
								// 		console.log('续方通知失败了')
								// 	}
								// });
							}else{
								uni.showToast({
									title: '操作失败！',
									duration: 3000
								})
							}
						})
					},
					getDrugListByRecipeId(){
						let data={
							recipeId: this.recipeId,
							medOfficinaInfoId: this.medOfficinaInfoId
						}
						this.func.$request('repRecipe/getDrugListByRecipeId.tz',data,'GET').then(res=>{
							if (res.data.success = true) {
								this.drugList = res.data.result
								let allPrice = 0
								this.drugList.forEach(item=>{
									allPrice += item.num*1*item.drugPrice
								})
								this.allPrice = allPrice
							}
							if(!this.drugList||this.drugList.length==0){
								uni.showToast({
									title: '您选择的药房不符合您的购药需求，请重新选择药房',
									icon: 'none'
								})
							}
						})
					}
				}
			};
</script>

<style lang="less">
	.my-yao{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: calc(100% - 40rpx );
		margin-bottom: 20rpx;
		color: #999999;
	}
	.drug-row{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: calc( 100% - 40rpx );
		margin-top: 20rpx;
	}
</style>
